import streamlit as st

from api.redbook_api import get_redbook_content

st.set_page_config(layout="wide")

st.title("📕小红书文案生成器")

# 定义布局（侧边栏）
with st.sidebar:
    #  定义标题
    st.divider()
    # 通义⼤模型密钥输⼊
    key = st.text_input("请输⼊通义大模型api key：")
    # key获取跳转链接
    st.page_link(
        "https://bailian.console.aliyun.com/?spm=5176.28326591.0.0.40f76ee1vUR5Of&accounttraceid=d873c9fe82ea443d9f3170f30dd5690cfnng#/api_key",
        label="⽆key？请点我获取", icon="♿")

    st.divider()

st.header("📕小红书文案成器")
subject = st.text_input("请输入文章主题")
temperature = st.slider("创造性", min_value=0.0, max_value=2.0, value=1.0, step=0.1)
flag = st.button("生成")
if flag:
    if not key:
        st.info("请先输入通义大模型api key")
        st.stop()
    if not subject:
        st.info("请输入文章主题")
        st.stop()

    # Create a list to store the results
    results = []

    # Create a placeholder for the table
    table_placeholder = st.empty()

    # Generate 6 sets of content
    for _ in range(6):
        with st.spinner("正在生成文案，请稍等🥵🥵🥵"):
            title, response = get_redbook_content(key, subject, temperature)
            results.append({"标题": title, "正文": response})

            # Update the table
            table_placeholder.table(results)
